Ccay.Module.define("Ccay.example.ui.igird.scrollLoadFunction", function(page, $S) {
	page.ready = function () {
		
		var gridOption1 = {
			height: 300,
			editMode: true,
			lazyLoad: true, // 滚动加载
			storageOp:{
				cache: true, // 是否缓存数据
				cacheKey: ["id"] // 缓存key
			},
	        columns: [
				 {columnType: "select", multi: true},
				 {field: 'id', width: 100, header: 'id', editable: false},
 			     {field: 'name', width:100, header: "name", rule: {required: true}},
 				 {field: 'description', width:200, header: "description"}
	        ],
		    ajax: {
		    	url: 'services/ccay/demo/grid/list/ranged/${start}/${end}/${orderBy}/${total}'
		    },
		    operation: {
		    	search: {
		    		btn: '#btnScrollSearch',
					panel: '#scrollLoadForm'
		    	},
		    	del: {
		    		btn: '#btnScrollDel',
		    		undoBtn: '#btnScrollUndoDel'
		    	},
		    	insert: {
		    		btn: '#btnScrollAdd',
		    		copy: true,
		    		clear: ['id']
		    	},
		    	save: {
		    		btn: '#btnScrollSave',
		    		ajax: {
		    			url: "services/ccay/demo/grid/batch"
		    		}
		    	}
		    }
	    };
		
		var gridOption2 = {
			height: 300,
			allowSort: true,
			editMode: true,
			lazyLoad: true,
			storageOp:{
				cacheData: true, // 是否缓存数据
				cacheKey: ["id"] // 缓存key
			},
			rowRender: "rowSpan",
	        columns: [
				 {columnType: "select", multi: true},
 			     {field: 'name', width:100, header: "name", rowSpan: true, rule: {required: true}},
 				 {field: 'description', width:200, header: "description"},
 				 {field: 'id', width: 100, header: 'id', editable: false}
	        ],
		    ajax: {
		    	url: 'services/ccay/demo/grid/list/ranged/${start}/${end}/${orderBy}/${total}'
		    },
		    operation: {
		    	search: {
		    		btn: '#btnUniteSearch',
					panel: '#rowUniteForm'
		    	},
		    	del: {
		    		btn: '#btnUniteDel',
		    		undoBtn: '#btnUniteUndoDel'
		    	},
		    	insert: {
		    		btn: '#btnUniteAdd',
		    		copy: true,
		    		clear: ['id']
		    	},
		    	save: {
		    		btn: '#btnUniteSave',
		    		ajax: {
		    			url: "services/ccay/demo/grid/batch"
		    		}
		    	}
		    }
	    };
		
	    var gridOption3 = {
			height: 300,
			editMode: true,
			lazyLoad: true,
			storageOp:{
				cacheData: true, // 是否缓存数据
				cacheKey: ["id"] // 缓存key
			},
			rowRender: "group",
			/*rowRenderOp: {groupExpand: false},*/
	        columns: [
				 {columnType: "select", multi: true},
				 {field: 'id', width: 100, header: 'id', editable: false},
 			     {field: 'name', width:100, header: "name", group: true, rule: {required: true}},
 				 {field: 'description', width:200, header: "description"}
	        ],
		    ajax: {
		    	url: 'services/ccay/demo/grid/list/ranged/${start}/${end}/${orderBy}/${total}'
		    },
		    operation: {
		    	search: {
		    		btn: '#btnGroupSearch',
					panel: '#rowGroupForm'
		    	},
		    	del: {
		    		btn: '#btnGroupDel',
		    		undoBtn: '#btnGroupUndoDel'
		    	},
		    	insert: {
		    		btn: '#btnGroupAdd',
		    		copy: true,
		    		clear: ['id']
		    	},
		    	save: {
		    		btn: '#btnGroupSave',
		    		ajax: {
		    			url: "services/ccay/demo/grid/batch"
		    		}
		    	}
		    }
	    };
		
	    var datas = [];
		for(var i = 1;i <= 100;i++)
		{	
			datas.push({id: i, name:'NO - ' + i});
		}
		
		var gridOption4 = {
			height: 220,
			lazyLoad: true,
			storageOp:{
				cacheData: true, // 是否缓存数据
				cacheKey: ["id"] // 缓存key
			},
	        columns: [
				{columnType: "select", multi: false},
	            {width: '100px', field: 'id', header: 'id'},
	  		    {width: '100px', field: 'name', header: 'name'}
	        ]
    	};
    	
    	$S("#scrollLoadDemo").ccayTab();
    	
		//点击tab头后，才加载数据，只第一次生效
		$S("#hd1").one("click", function () {
			$S("#iStudent4").igrid(gridOption4, datas);
		});
		
		$S("#hd2").one("click", function () {
			 $S("#iStudent1").igrid(gridOption1);
		});
		
		$S("li[tabid='tab3']").one("click", function () {
			$S("#iStudent2").igrid(gridOption2);
		});
		
		$S("li[tabid='tab4']").one("click", function () {
			 $S("#iStudent3").igrid(gridOption3);
		});
	    
		
	};
	
	page.operateTest = function (value) {
		alert(Ccay.DataHelper.toJsonStr(value));
	};
	
	page.openDemo = function(tabId){
		$S("#scrollLoadDemo").getCcayTabManager().selectItem(tabId);
	};
	
});